export class DateUtil {

    /**
     * 格式化日期输出
     * @param date 日期，默认为今天
     * @param format 格式化格式，默认为yyyy-MM-dd HH:mm:ss
     */
    static formatDate(date: Date = new Date(), format: string = "yyyy-MM-dd HH:mm:ss"): string {
        const dict: Record<string, any> = {
            yyyy: date.getFullYear(),
            M: date.getMonth() + 1,
            d: date.getDate(),
            H: date.getHours(),
            m: date.getMinutes(),
            s: date.getSeconds(),
            MM: ('' + (date.getMonth() + 101)).substring(1),
            dd: ('' + (date.getDate() + 100)).substring(1),
            HH: ('' + (date.getHours() + 100)).substring(1),
            mm: ('' + (date.getMinutes() + 100)).substring(1),
            ss: ('' + (date.getSeconds() + 100)).substring(1),
        };
        return format.replace(/(yyyy|MM?|dd?|HH?|mm?|ss?)/g, () => dict[arguments[0]]);
    }
}